class Solution {
public:
    int mySqrt(int x) {
        int left=1,right=x/2;
        while(left<right)
        {
            int mid=left+(right-left)/2;
            if(mid<x/mid)
            {
                left=mid+1;
            }
            else{
                right=mid;
            }
        }
        if(left>x/left)
            left--;
        return left;
    }
};
